<?php

use Workerman\Worker;

require_once __DIR__ . '/vendor/autoload.php';

// 子进程
$worker =new Worker("http://0.0.0.0:1234");

$worker->onWorkerStart = function (Worker $task){
    //连接服务器
    \Channel\Client::connect('127.0.0.1', 2206);

    //订阅
    \Channel\Client::on('user_login', function ($data) use($task){
        echo 'user_login:'.$data.'\r\n';

        //取消订阅
        \Channel\Client::unsubscribe('user_login');
    });
};

$worker->onMessage = function (\Workerman\Connection\TcpConnection $connection,\Workerman\Protocols\Http\Request $requst){
    echo $requst->path().'\r\n';

    //发布通知
    \Channel\Client::publish('user_login',$requst->path());
};


Worker::runAll();